<?php 
	include "../../config.php";
	include ADMIN_ROOT."templates/header.php";
	include ADMIN_ROOT."templates/left.php";
	require_once DOC_ROOT."/lib/connection.php";
	include DOC_ROOT."/lib/ckeditor/ckeditor.php";
	include DOC_ROOT."/lib/ckfinder/ckfinder.php";
?>
<div class="main-content">
<?php
		if(!$_POST){// Neu nguoi dung chua submit du lieu
			$con = sqlsrv_connect(SERVER,$conInfo);
			$stmt= sqlsrv_query($con,"SELECT * FROM category");
			
			include_once ADMIN_ROOT."views/post/add.php";
			$ck = new CKEditor();
			$ck->basePath = URL_ROOT."/lib/ckeditor/";
			$config['toolbar'] = array(
				array('-', 'Bold', 'Italic', 'Underline', 'Strike'),
				array( 'Image', 'Link', 'Unlink', 'Anchor' ));
			$ck->replace("txtIntro",$config);
						
			$ck1 = new CKEditor();
			$ck1->basePath = URL_ROOT."/lib/ckeditor/";
			CKFinder::SetupCKEditor( $ck1,URL_ROOT.'/lib/ckfinder/');
			$ck1->replace("txtContent");
		}
		else{
			$subject = $_POST['txtSubject'];
			$intro   = $_POST['txtIntro'];
			$content = $_POST['txtContent'];
			$status  = $_POST['chStatus'];
			$status  = $status=="on"?1:0;
			$fimg=$_POST['txtFImage'];
			$cateID=$_POST['slCateId'];

			$con = sqlsrv_connect(SERVER,$conInfo);
			$stmt= sqlsrv_query($con,"INSERT INTO posts VALUES(?,?,?,?,?)",array($subject,$intro,$content,$status,$fimg,));
			header("location:index.php");
		}
	?>
</div>
<?php
 	include ADMIN_ROOT."templates/footer.php";
 ?>

